import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import store from './store'
Vue.config.productionTip = false
App.mpType = 'app'

import uView from '@/uni_modules/uview-ui'
Vue.use(uView)

// 引入uView对小程序分享的mixin封装
let mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js');
Vue.mixin(mpShare);
Vue.prototype.$store = store
// store处理
let vuexStore = require("@/store/$u.mixin.js")
Vue.mixin(vuexStore)

try {
  function isPromise(obj) {
    return (
      !!obj &&
      (typeof obj === "object" || typeof obj === "function") &&
      typeof obj.then === "function"
    );
  }

  // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  uni.addInterceptor({
    returnValue(res) {
      if (!isPromise(res)) {
        return res;
      }
      return new Promise((resolve, reject) => {
        res.then((res) => {
          if (res[0]) {
            reject(res[0]);
          } else {
            resolve(res[1]);
          }
        });
      });
    },
  });
} catch (error) { }

const app = new Vue({
  ...App
})

// 封装that.$goUrl
Vue.prototype.$goUrl = (path,type,params)=>{
	uni.$u.route({
		type: type,
		url: path,
		params: params?params: {}
	});
}

// 封装that.$log
Vue.prototype.$log = (text) => {
  if (process.env.NODE_ENV === 'development') {
    console.log(text)
  }
}

// http拦截器，将此部分放在new Vue()和app.$mount()之间，才能App.vue中正常使用
require('@/common/http.interceptor.js')(app)

app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif